﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace WebDAVInterfaceConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            List("serverUrl", "name", "password");
            Console.ReadLine();
        }

        private static void List(string CourantHREF, string sUserName, string sPassword)
        {
            var req = (HttpWebRequest)WebRequest.Create(CourantHREF);
            req.Method = "GET";

            // s'authentifie
            if (!String.IsNullOrEmpty(sUserName))
            {
                var networkCredential = new NetworkCredential(sUserName, sPassword);
                req.Credentials = networkCredential;
            }

            var webResp = req.GetResponse();
            var stream = webResp.GetResponseStream();
            var sr = new StreamReader(stream);
            var sResponse = sr.ReadToEnd();

            var linkRegExp = new Regex(@"<A\b[^>]*>(.*?)</A>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            var mainMatches = linkRegExp.Matches(sResponse);
            foreach (string strLink in from Match linkMatch in mainMatches select linkMatch.Value)
            {
                Console.WriteLine(strLink);
            }
            webResp.Close();
        }
    }
}
